import {
    ConfigService, LoggerService, LoggerInfo, ContextService, ValidationService, ValidationType
} from '../../framework';
import { Component, Input, OnInit } from '@angular/core';
import { IComponent } from './base.interface';
import { TranslateService } from 'ng2-translate';

@Component({
    selector: 'base',
    template: '',
    styleUrls: ['./base.component.scss'],
    // providers: [ConfigService, LoggerService, ContextService, ValidationService, TranslateService]
})
export class BaseComponent implements IComponent, OnInit {
    skin: any;
    style: any;
    global: any;
    context: any;
    lanEn: boolean = false;
    @Input() input: any;
    constructor(
        private _config: ConfigService,
        private _logger: LoggerService,
        private _context: ContextService,
        private _validate: ValidationService,
        private _translate: TranslateService, ) {
        this.getContext();
    }

    ngOnInit() {
        let validateTypes = [
            ValidationType.NotEmpty,
            ValidationType.NotNull,
        ];
        let result = this._validate.checkingAllPass(validateTypes, this.input);
        if (!result) {
            this._logger.warning(new LoggerInfo('BaseComponent', 'input para is null or empty', null));
        }
    }

    updateSkin(): void {
        this.skin = this._config.getValueByKey('wit-skin');
        //TODO
    }

    updateStyle(): void {
        this.style = this._config.getValueByKey('wit-style');
        //TODO
    }

    updateGlobal(): void {
        this.global = this._config.getValueByKey('wit-global');
        this.global === 'en-us' ? this.lanEn = true : this.lanEn = false;
        this._translate.use(this.global);
    }

    private getContext() {
        this.context = ContextService.CurrentContext;
    }
}